/**
 * Class TabBar
 * mange tabs and tabbars
 */
TabBar = (function(_super){

    __extends(TabBar, _super);
    /**
     * TabBar constructor
     * @param view {String|View|HTMLElement} id, view or html element
     * @constructor
     */
    function TabBar(view){
        var _button, _i, _len, _ref;
        TabBar.__super__.constructor.call(this);
        this.setContentView(view);
        this._buttons = this.view.selectAll(".button-holder", true);
        this._active = null;
        this.buttons = [];

        _ref = this._buttons;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            _button = new Button(_ref[_i]);
            this.buttons.push(_button);
        }
    }
    /**
     * Get active tab
     * @returns {Button} active tab
     */
    TabBar.prototype.getActive = function(){
        return this.buttons[this._active];
    };
    /**
     * Set active tab by index
     * @param index {Number} index of button that we want to make active
     */
    TabBar.prototype.setActive = function(index){
        this._active = index;
        this.buttons[index].addClass('active');
    };
    /**
     * Remove active by index
     * @param index {Number} index of button
     */
    TabBar.prototype.removeActive = function(index){
        this._active = null;
        this.buttons[index].removeClass('active');
    };
    /**
     * Set on tab selected listener
     * @param listener {Function} tab selected listener
     */
    TabBar.prototype.setOnTabSelectedListener = function(listener){
        this.tabSelectedListener = listener;
        this.setOnClickListeners();
    };
    /**
     * Set click listener for all buttons
     */
    TabBar.prototype.setOnClickListeners = function(){
        var _i, _len;
        for(_i = 0, _len = this.buttons.length; _i < _len; _i++){
            if(this.tabSelectedListener) this.buttons[_i].setOnClickListener(this.tabSelectedListener, _i);
        }
    };

    return TabBar;

})(Base);